const request = require("/util/request")
const app = getApp()


// 小程序首页
export function home(){
    return request({
        url:'api/appSysHome/find',
        method:'GET'
    })
}
// 小程序分类
export function type(){
    return request({
        url:'api/product-type/all',
        method:'GET'
    })
}

// 查询优惠券
export function couponUser() {
    return request({
        url: `api/couponUser/app/query/count`,
        method: 'GET',
    })
}

// 查询收藏夹
export function favorites() {
    return request({
        url: 'api/product/app/favorites',
        method: 'GET',
    })
}

// 查看推荐
export function eventsGoods(){
    return request({
        url: 'api/appSysHome/find/eventsGoods',
        method: 'GET',
    })
}

// 首页底部三模块
export function simpleProduct(data){
    return request({
        url: 'api/product/app/simpleProduct',
        method: 'POST',
        data: data
    })
}


// 上传
export function uploadFile(path,appUrl){
	console.log('path', path)
    return new Promise((resolve,reject)=>{
        my.uploadFile({
            url: appUrl + '/api/file/upload',
            // url: 'https://api.lezuxia.cn/api/file/upload',
            fileType: 'image',
            fileName: 'file',
            filePath: path,
            formData: {
                path: 'mini'
            },
            header: {
                'Content-Type': 'multipart/form-data', // 只能是这种形式
            },
            success: res => {
                resolve(res)
            },
            fail: err => {
                console.log(err)
                my.showToast({
                    content: '请重新上传', // 文字内容
                });
            }
        })
    })
}


// 商家入驻申请
export function applyBusiness(data){
  return request({
      url: 'api/shop/app/apply-business',
      method: 'POST',
      data: data
  })
}

// 商家券活动
export function queryActivity(data){
  return request({
    url: 'api/merchantVoucher/queryActivity',
    method: 'GET',
  })
}

// 领商家券
export function merchantVoucherEdit(data){
  return request({
      url: 'api/merchantVoucher/receiveMerchantVoucher',
      method: 'POST',
      data: data
  })
}